package user

import (
	"cross-shard-channel/ledger"
	"github.com/eywa-protocol/bls-crypto/bls"
)

func GetShard(pub bls.PublicKey) int {
	bytes := pub.Marshal()
	fir := int(bytes[0])
	shardNum := fir % ledger.SHARDNUM

	return shardNum
}

func GenerateKeyWithPub(TarPub bls.PublicKey) (bls.PrivateKey,bls.PublicKey){
	for {
		pri,pub := bls.GenerateRandomKey()
		tarShard := GetShard(TarPub)
		if GetShard(pub) == tarShard && GetShard(TarPub.Aggregate(pub)) == tarShard {
			return pri,pub
		}
	}
}
